// pages/mysale/my_sale_team/my_sale_team.js
const app = getApp();
var router = require("../../../router.js");
Page({
   
  /**
   * 页面的初始数据
   */
  data: {
      nav_flag:0,
      list_data:[],
      team:[
          {
              name:'一级',
              num:'0',
              list:[                  
              ]
          },
          {
              name: '二级',
              num: '0',
              list: [                  
              ]
          }
      ]
  },

  change_nav(e) {
    var index = e.currentTarget.dataset.index;
    this.setData({
      list_data: this.data.team[index].list,
      nav_flag: index
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    app.request({
      url: router.user.team,
      method: "POST",
      data: {
        userId: wx.getStorageSync('userInfo').id,
      },
      success: function (data) {
        console.log(data);
        if (data.status == true) {
          // if (data.one_level.length > 0){
          that.data.team[0].list.push(data.one_level[0]);
          // }        
          that.data.team[0].num = data.one_num;
          that.data.team[1].num = data.two_num;
          for (var i = 0; i < data.two_level.length; i++){            
            that.data.team[1].list.push(data.two_level[i]);
          }
          console.log(that.data.team[0].list,'that.data.team[0].list')
          console.log(that.data.team[1].list, 'that.data.team[1].list')
          that.setData({
            team: that.data.team,
            list_data: that.data.team[0].list
          });  
          console.log(that.data.team);       
        } else {
          wx.showToast({
            title: '获取信息失败',
            icon: 'none',
            mask: true,
            duration: 2000
          });
        }
      }
    })
  }
})